import { Router } from 'express'
import { find } from '../../db/dao'
import { PROFILE } from '../../db/model'

const router = Router()

router.get('/list', function (req, res) {
  const { id } = req.query
  const promise = id ? find(PROFILE, { _id: id }) : find(PROFILE)
  promise.then(profiles => {
    if (profiles.length === 0) {
      return res.status(403).send('账单不存在')
    }
    res.json(profiles)
  }).catch(() => {
    res.status(500).json()
  })
})

export default router
